import {hrAjax as proFetch} from 'src/hrpub/common/utils/utils';

export default function checkTransData(param_str) {
    const {editTable, orgVal, transType, transState, func_type} = this.props;
    let postData = {
        func_type,
        inout: transType,
        model: {areacode: 'PsnReceive', rows: editTable.getAllRows('PsnReceive')},
        param_str,
        pk_org: orgVal.refpk,
        transstate: transState
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsPsntransterReceiveDoCheckAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                if (res.data.confirmMsg) {
                    this.alertModalNode.show([res.data.confirmMsg], null, () => {
                        saveTransData.call(this, param_str)
                    })
                } else {
                    saveTransData.call(this, param_str)
                }
            }
        });
}

function saveTransData(param_str) {
    const {editTable, orgVal, transType, transState, func_type} = this.props;
    const {isFinshPart, isSynWork} = this.state;
    let postData = {
        func_type,
        inout: transType,
        model: {areacode: 'PsnReceive', rows: editTable.getAllRows('PsnReceive')},
        isFinshPart,
        isSynWork,
        param_str,
        pk_org: orgVal.refpk,
        transstate: transState
    };

    return proFetch({
        url: '/nccloud/hrtrn/pub/RecordsPsntransterReceiveDoAction.do',
        body: postData,
    })
        .then((res) => {
            if (res.success) {
                if (!res.data) {
                    editTable.setTableData('hi_psntranster1', {
                        rows: []
                    });
                } else {
                    editTable.setTableData('hi_psntranster1', {
                        rows: res.data['hi_psntranster1'].rows
                    });
                }
                this.closeSubModal();
                this.closeModal();
            }
        });
}
